Create folder to your FTP server with PHP

You need to connect first to your FTP server and you need global $connection_id after that you can use this function.

==============================================================

function create_folder($dir){

	///Use the global connection_id
	global $connection_id;

	///Check if folder already exists.
	if (@ftp_chdir($connection_id, $dir)) {
		
		@ftp_chdir($connection_id, '..');

		///If you can access the folder send error and false, we failed.
                echo '<div class="error">Error: Folder exists already</div>';
		return false;
	
	/// If we cant access it we can create it so lets create it.
	} else {
	
		/// Create folder
		if (ftp_mkdir($connection_id, $dir)) {
	
			/// On success we return true.
			return true;
			
		} else {
				
			/// We failed, print error message and return false
			echo '<div class="error">Error: Creation failed for unknown reason</div>';
			return false;
			
		}
	
	}

}